package com.net.oil.shop;

import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import android.text.TextUtils;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.widget.ImageView;
import android.widget.TextView;

import com.net.oil.R;
import com.net.oil.app.Constant;
import com.net.oil.util.WebViewUtil;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 商家介绍
 */
public class ShopIntroduceActivity extends AppCompatActivity {

    @BindView(R.id.toolbar_go_back)
    ImageView toolbarGoBack;
    @BindView(R.id.toolbar_title)
    TextView toolbarTitle;
    @BindView(R.id.web_view)
    WebView webView;
    private String shopIntroduce;

    private WebSettings webSetting;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_shop_introduce);
        ButterKnife.bind(this);
        initData();
        initView();
    }

    private void initView() {
        toolbarTitle.setText("详情");
        webSetting = webView.getSettings();
        webSetting.setTextZoom(100);
        webSetting.setJavaScriptEnabled(true);
        webSetting.setUseWideViewPort(true);  //将图片调整到适合webview的大小
        webSetting.setLoadWithOverviewMode(true); // 缩放至屏幕的大小
    }

    private void initData() {
        shopIntroduce = getIntent().getStringExtra(Constant.INTENT_SHOP_INTRODUCE_KEY);
        if (!TextUtils.isEmpty(shopIntroduce)){
            webView.loadData(WebViewUtil.getHtmlData(shopIntroduce), "text/html; charset=UTF-8", null);
        }
    }

    @OnClick(R.id.toolbar_go_back)
    public void onViewClicked() {
        finish();
    }
}
